__author__ = "Francesco di Dio, Simone Pasculli"
__copyright__ = "Copyright 2014, The M.A.D.S. Project"
__credits__ = ["none",]
__license__ = "GPL"
__version__ = "1.0.1"
__maintainer__ = "Francesco di Dio, Simone Pasculli"
__email__ = "tabuto83@gmail.com"
__status__ = "Development"
'''
This module used for scratch code or test M.A.D.S. functions
'''

import random
import string

class SimElement():

    def __init__(self,name='None',rating=0,color=0,cost=1,weight=1 ):
        self.name=name
        self.rating = rating
        self.color = color
        self.cost=cost
        self.weight = weight

    def __str__(self):
        return 'SimElement['+self.name+'] rate['+str(self.rating)+'] color['+str(self.color)+'] cost['+str(self.color)+'] weight['+str(self.weight)+']'


class SimDeck():
    def __init__(self):
        self.deck = {}

    def addEle(self,e):
        self.deck[e.name] = e;

    def addEleDict(self,d):
        for e in d.keys():
            self.addEle(e)

    def addDeck(self,d):
        self.addEleDict(d.deck)

    def __str__(self):
        result = ''
        for k in self.deck.keys():
            result = result + str(self.deck[k])+'\n'
        return result


class Bucket():
    '''
    Represent a bucket with a certain size.
    For each bucket element is specified a size
    using a list with sizes
    For example:
    Buckets(3,(3,5,2))
    create a buckets of size 3.
    The first element has length 3
    The 2nd one has length 5
    The 3rd one has length 2
    '''
    def __init__(self,size=1,capacity=(1,)):
        self.buckets={}
        for i in range(size):
            self.buckets[i] = [0]*capacity[i]

    def __str__(self):
        result = ''
        for i in self.buckets.keys():
            result = result + '\n'+str(i)+') size: ' + str(len(self.buckets[i])  )
            for e in range(len(self.buckets[i])):
                result=result +'\n\t\t'+ str( self.buckets[i][e])
        return result

    def addEle(self,ele,bucket=0,pos=-1):
        l = self.buckets[bucket]
        if(pos>-1):
            l[pos]=ele
            return True
        else:
            for i in range(len(l)):
                if(l[i]==0):
                    l[i]=ele
                    return True
        return False


    def getEle(self,b,pos):
        l = self.buckets[b]
        return l[pos]

    def getBucket(self,b):
        return self.buckets[b]




def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

def createDeck(size=10):
    d = SimDeck()
    for i in range(size):
        d.addEle( SimElement(id_generator(6),  random.randint(0, 5),random.randint(1, 4),random.randint(1, 100),random.randint(1, 15) ))
    return d




d = createDeck(10)
print str(d)


b = Bucket(3,(2,5,3))

ele = d.deck[d.deck.keys()[0]]
b.addEle(ele,1)

print str(b)

